package com.linewow.xhyy.nihaonew.adapter;

import android.content.Context;
import android.widget.ImageView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.linewow.xhyy.nihaonew.R;
import com.linewow.xhyy.nihaonew.entity.ImessageInfo;
import com.linewow.xhyy.nihaonew.entity.user.Uinfo;
import com.squareup.picasso.Picasso;

import java.util.List;

/**
 * Created by LXR on 2016/10/17.
 */
public class ImessageAdapter extends BaseQuickAdapter<ImessageInfo<Uinfo>> {

    private Context context;

    private String TAG="ImessageAdapter";

    public ImessageAdapter(List<ImessageInfo<Uinfo>> data) {
        super(R.layout.item_imessage,data);
    }
    @Override
    protected void convert(BaseViewHolder baseViewHolder, ImessageInfo<Uinfo> imessageInfo) {
        if(context==null){
            context=baseViewHolder.getConvertView().getContext();
        }
        Uinfo uinfo=imessageInfo.uinfo;
        baseViewHolder.setText(R.id.item_imessage_way,imessageInfo.extf1);
        baseViewHolder.setText(R.id.item_imessage_time,imessageInfo.time);
        if(imessageInfo.type.equals("pinglun")){
            baseViewHolder.setVisible(R.id.item_imessage_content,true);
            baseViewHolder.setText(R.id.item_imessage_content,imessageInfo.extf3);
        }else{
            baseViewHolder.setVisible(R.id.item_imessage_content,false);
        }
        baseViewHolder.setText(R.id.item_imessage_nick,uinfo.nickname);
        ImageView itemImessageAvatar=baseViewHolder.getView(R.id.item_imessage_avatar);
        baseViewHolder.addOnClickListener(R.id.item_imessage_avatar);
        Picasso.with(context).load(imessageInfo.avatar.replace("m.en1on1.com", "huibenabc.com")).error(R.mipmap.err_avatar).fit().into(itemImessageAvatar);
    }


}
